import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:image_picker/image_picker.dart';
import 'package:wu_you/data/cache/id_cache.dart';
import 'package:wu_you/data/cache/username_password_cache.dart';
import 'package:wu_you/data/repository/auth_repository.dart';
import 'package:wu_you/data/repository/trad_repository.dart';
import 'package:wu_you/l10n/messages.dart';
import 'package:wu_you/model/user/trad_model.dart';
import 'package:wu_you/res/colors.dart';
import 'package:wu_you/state/bloc/http_bloc.dart';
import 'package:wu_you/state/bloc/trad_bloc.dart';
import 'package:wu_you/utils/extension_utils.dart';
import 'package:wu_you/utils/utils.dart';
import 'package:wu_you/utils/utils_image.dart';
import 'package:wu_you/widgets/countdown_view.dart';
import 'package:wu_you/widgets/http_status_widget.dart';

///收款方式
class TradPaymentPage extends StatefulWidget{
  @override
  TradPaymentPageState createState() => TradPaymentPageState();
}
class TradPaymentPageState extends State<TradPaymentPage>{
  List<String> _tabs = [];

  var message;
  int _index = 0;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    _tabs.clear();
    _tabs = ['${message['text22']}','${message['text23']}','${message['text30']}','${message['text24']}','${message['text26']}'];
    return DefaultTabController(
      length: _tabs.length,
      child: Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          title: Text("${message['text27']}"),
        ),
        body: Column(
          children: [
            TabBar(
              labelColor: AppColors.primaryColor,
              indicatorColor: AppColors.primaryColor,
              unselectedLabelColor: AppColors.textColor,
              indicatorSize: TabBarIndicatorSize.label,
              isScrollable: true,
              tabs: _tabs.map((e) => Tab(text: e,)).toList(),
              onTap: (index){
                setState(() {
                  _index = index;
                });
              },
            ),
            SizedBox(height: 6,),
            Expanded(
              child: TabBarView(
                children: [
                  BankPaymentView(index: 1,),
                  ZfbPaymentView(index: 2),
                  TngPaymentView(index: 5),
                  WxPaymentView(index: 3,),
                  UsdtPaymentView(index: 4)
                ],
              )
            )
          ],
        ),
      )
    );
  }
}

///银行卡
class BankPaymentView extends StatefulWidget{
  final int index;
  BankPaymentView({Key key,this.index}):super(key: key);
  @override
  BankPaymentViewState createState() => BankPaymentViewState();
}
class BankPaymentViewState extends State<BankPaymentView>{
  String bankName;
  String name;
  String idCard;
  String bankNum;
  String mobile;

  String _smsCode;
  final _countdownKey = GlobalKey<CountdownViewState>();

  String phone;
  @override
  void initState() {
    super.initState();

    UserPhoneCache cache = UserPhoneCache();
    cache.get().then((value){
      phone = value;
    });

    // UsernamePasswordCache cache = UsernamePasswordCache();
    // cache.getArray().then((value) {
    //   phone = value[0];
    // });
  }
  BuildContext ctx;

  ///status    1审核    0拒绝


  int showSmsView = 1;
  int showBtn = 1;

  var message;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    return Scaffold(
      appBar: AppBar(
        title: Text("${message['text22']}"),
      ),
      backgroundColor: Colors.white,
      body: HttpWidget<PaymentInfo, PaymentInfoBloc>(
          create: (context) => PaymentInfoBloc()..add(IdHttpEvent(widget.index)),
          emptyBuilder: (context){
            ctx = context;
            return Column(
              children: [
                ListTile(
                  leading: Text("${message['text1']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this.bankName = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: bankName),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text2']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this.name = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: name),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text4']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("身份证号",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this.idCard = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: idCard),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "请输入身份证号",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text5']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this.bankNum = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: bankNum),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text6']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this.mobile = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: mobile),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text12']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                TextFormField(
                  style: TextStyle(color: Colors.black,fontSize: 15),
                  maxLines: 1,
                  textAlignVertical: TextAlignVertical.center,
                  textInputAction: TextInputAction.done,
                  // maxLength: 4,
                  keyboardType: TextInputType.numberWithOptions(),
                  autofocus: false,
                  obscureText: false,
                  cursorColor: Theme.of(context).primaryColor,
                  validator: (value) {
                    return value.length == 0 ? '${message['paymentSms']}' : null;
                  },
                  onChanged: (value){
                    _smsCode = value;
                  },
                  controller: TextEditingController(text: _smsCode),
                  decoration: InputDecoration(
                    fillColor: Colors.white,
                    filled: true,
                    prefixIconConstraints: BoxConstraints.loose(Size(85, 50)),
                    suffixIconConstraints: BoxConstraints.loose(Size(100, 56)),
                    suffixIcon: CountdownView(
                      key: _countdownKey,
                      hint: Text(
                        "${message['getCode']}",
                        style: TextStyle(color: AppColors.primaryColor, fontSize: 14),
                      ),
                      onPressed: () {
                        closeKeyboard(context);
                        _onGetCode();
                      },
                    ),
                    border: UnderlineInputBorder(
                      borderSide: BorderSide.none,
                      borderRadius: const BorderRadius.all(Radius.circular(24)),
                    ),
                    errorMaxLines: 1,
                    counterText: '',
                    contentPadding: EdgeInsets.only(left: 20, right: 16),
                    hintText: "${message['paymentSms']}",
                    hintStyle: TextStyle(fontSize: 15,color: AppColors.textHintColor),
                    prefixIcon: Center(
                      child: Text(
                          "${message['text13']}",
                          style: TextStyle(color: AppColors.textColor,fontSize: 16)
                      ),
                    ),
                  ),
                ),
                Divider(),

                SizedBox(height: 30,),
                SizedBox(
                  width: double.infinity,
                  height: 42,
                  child: ElevatedButton(
                    child: Text("${message['text15']}"),
                    style: ButtonStyle(
                      backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                      shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                    ),
                    onPressed: (){
                      subBank();
                    },
                  ),
                ).addPadding(EdgeInsets.only(left: 15,right: 15)),
              ],
            );
          },
          child: (context, data) {
            ctx = context;
            List<String> list =  data.content.split("|");
            if(showSmsView == 1){
              bankName = list[0];
              name = list[1];
              bankNum = list[2];
              idCard = list[3];
              mobile = data.mobile;
              return Column(
                children: [
                  ListTile(
                    leading: Text("${message['text1']}",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this.bankName = value;
                      },
                      enabled: false,
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: bankName),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "${message['text2']}",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  ListTile(
                    leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this.name = value;
                      },
                      enabled: false,
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: name),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "${message['text4']}",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  ListTile(
                    leading: Text("身份证号",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this.idCard = value;
                      },
                      enabled: false,
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: idCard),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "请输入身份证号",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  ListTile(
                    leading: Text("${message['text5']}",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this.bankNum = value;
                      },
                      enabled: false,
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: bankNum),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "${message['text6']}",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  ListTile(
                    leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this.mobile = value;
                      },
                      enabled: false,
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: mobile),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "${message['text12']}",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  SizedBox(height: 30,),
                  Offstage(
                    offstage: showBtn == 1 ? false : true,
                    child: SizedBox(
                      width: double.infinity,
                      height: 42,
                      child: ElevatedButton(
                        child: Text(data.status == "1" ? "${message['text16']}" : "${message['text21']}"),
                        style: ButtonStyle(
                          backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                          shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                        ),
                        onPressed: (){
                          if(data.status == "1"){
                            return;
                          }
                          showSmsView = 2;
                          showBtn = 2;
                          setState(() {});
                        },
                      ),
                    ).addPadding(EdgeInsets.only(left: 15,right: 15)),
                  ),
                  Offstage(
                    offstage: showBtn == 2 ? false : true,
                    child: SizedBox(
                      width: double.infinity,
                      height: 42,
                      child: ElevatedButton(
                        child: Text(data.status == "1" ? "${message['text16']}" : "${message['text21']}"),
                        style: ButtonStyle(
                          backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                          shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                        ),
                        onPressed: (){
                          if(data.status == "1"){
                            return;
                          }

                          subBank();
                        },
                      ),
                    ).addPadding(EdgeInsets.only(left: 15,right: 15)),
                  ),

                  // SizedBox(height: 3,),
                  // Offstage(
                  //   offstage: data.status == "0" ? false : true,
                  //   child: Text("${message['text17']}",style: TextStyle(color: AppColors.primaryColor),),
                  // ),
                  // SizedBox(height: 8,),
                  // Offstage(
                  //   offstage: data.status == "2" ? false : true,
                  //   child: Text("${message['text29']}",style: TextStyle(color: AppColors.primaryColor),),
                  // )
                ],
              );
            }else{
              return Column(
                children: [
                  ListTile(
                    leading: Text("${message['text1']}",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this.bankName = value;
                      },
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: bankName),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "${message['text2']}",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  ListTile(
                    leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this.name = value;
                      },
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: name),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "${message['text4']}",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  ListTile(
                    leading: Text("身份证号",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this.idCard = value;
                      },
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: idCard),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "请输入身份证号",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  ListTile(
                    leading: Text("${message['text5']}",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this.bankNum = value;
                      },
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: bankNum),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "${message['text6']}",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  ListTile(
                    leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this.mobile = value;
                      },
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: mobile),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "${message['text12']}",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  Offstage(
                    offstage: showSmsView  == 2 ? false : true,
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        TextFormField(
                          style: TextStyle(color: Colors.black,fontSize: 15),
                          maxLines: 1,
                          textAlignVertical: TextAlignVertical.center,
                          textInputAction: TextInputAction.done,
                          // maxLength: 4,
                          keyboardType: TextInputType.numberWithOptions(),
                          autofocus: false,
                          obscureText: false,
                          cursorColor: Theme.of(context).primaryColor,
                          validator: (value) {
                            return value.length == 0 ? '${message['paymentSms']}' : null;
                          },
                          onChanged: (value){
                            _smsCode = value;
                          },
                          controller: TextEditingController(text: _smsCode),
                          decoration: InputDecoration(
                            fillColor: Colors.white,
                            filled: true,
                            prefixIconConstraints: BoxConstraints.loose(Size(85, 50)),
                            suffixIconConstraints: BoxConstraints.loose(Size(100, 56)),
                            suffixIcon: CountdownView(
                              key: _countdownKey,
                              hint: Text(
                                "${message['getCode']}",
                                style: TextStyle(color: AppColors.primaryColor, fontSize: 14),
                              ),
                              onPressed: () {
                                closeKeyboard(context);
                                _onGetCode();
                              },
                            ),
                            border: UnderlineInputBorder(
                              borderSide: BorderSide.none,
                              borderRadius: const BorderRadius.all(Radius.circular(24)),
                            ),
                            errorMaxLines: 1,
                            counterText: '',
                            contentPadding: EdgeInsets.only(left: 20, right: 16),
                            hintText: "${message['paymentSms']}",
                            hintStyle: TextStyle(fontSize: 15,color: AppColors.textHintColor),
                            prefixIcon: Center(
                              child: Text(
                                  "${message['text13']}",
                                  style: TextStyle(color: AppColors.textColor,fontSize: 16)
                              ),
                            ),
                          ),
                        ),
                        Divider(),
                      ],
                    ),
                  ),
                  SizedBox(height: 30,),
                  Offstage(
                    offstage: showBtn == 1 ? false : true,
                    child: SizedBox(
                      width: double.infinity,
                      height: 42,
                      child: ElevatedButton(
                        child: Text(data.status == "1" ? "${message['text16']}" : "${message['text21']}"),
                        style: ButtonStyle(
                          backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                          shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                        ),
                        onPressed: (){
                          if(data.status == "1"){
                            return;
                          }
                          showSmsView = 2;
                          showBtn = 2;
                          setState(() {});
                        },
                      ),
                    ).addPadding(EdgeInsets.only(left: 15,right: 15)),
                  ),
                  Offstage(
                    offstage: showBtn == 2 ? false : true,
                    child: SizedBox(
                      width: double.infinity,
                      height: 42,
                      child: ElevatedButton(
                        child: Text(data.status == "1" ? "${message['text16']}" : "${message['text21']}"),
                        style: ButtonStyle(
                          backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                          shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                        ),
                        onPressed: (){
                          if(data.status == "1"){
                            return;
                          }

                          subBank();
                        },
                      ),
                    ).addPadding(EdgeInsets.only(left: 15,right: 15)),
                  ),

                  // SizedBox(height: 3,),
                  // Offstage(
                  //   offstage: data.status == "0" ? false : true,
                  //   child: Text("${message['text17']}",style: TextStyle(color: AppColors.primaryColor),),
                  // ),
                  // SizedBox(height: 8,),
                  // Offstage(
                  //   offstage: data.status == "2" ? false : true,
                  //   child: Text("${message['text29']}",style: TextStyle(color: AppColors.primaryColor),),
                  // )
                ],
              );
            }
          }
      )
    );
  }

  _onGetCode(){
    _countdownKey.currentState.state = CountdownState.loading;
    LoadingApi.func(AuthRepository().getSmsCode(8,phone: phone), context,showLoading: false,complete: (value){
      _countdownKey.currentState.state = CountdownState.countdown;
      ToastUtils.show("$value", context);
    },error: (error){
      _countdownKey.currentState.state = CountdownState.init;
      ToastUtils.show("$error", context);
    });
  }
  void subBank(){
    if(bankName == null){
      ToastUtils.show("${message['text2']}", context);
      return;
    }
    if(name == null){
      ToastUtils.show("${message['text4']}", context);
      return;
    }
    if(idCard == null){
      ToastUtils.show("请输入身份证号", context);
      return;
    }
    if(bankNum == null){
      ToastUtils.show("${message['text6']}", context);
      return;
    }
    if(mobile == null){
      ToastUtils.show("${message['text12']}", context);
      return;
    }
    if(_smsCode == null){
      ToastUtils.show("${message['paymentSms']}", context);
      return;
    }
    closeKeyboard(context);
    LoadingApi.func(TradRepository().bindPayment(payment: widget.index,bankName: bankName,bankRealName: name,bankAccount: bankNum,code: _smsCode,mobile: mobile,idcard: idCard), context,complete: (e){
      ToastUtils.show("${message['Success']}", context);
      showSmsView = 1;
      showBtn = 1;
      BlocProvider.of<PaymentInfoBloc>(ctx).add(IdHttpEvent(widget.index));
    },error: (e){
      ToastUtils.show("$e", context);
    });
  }
}




///支付宝
class ZfbPaymentView extends StatefulWidget{
  final int index;
  ZfbPaymentView({Key key,this.index}):super(key: key);
  @override
  ZfbPaymentViewState createState() => ZfbPaymentViewState();
}
class ZfbPaymentViewState extends State<ZfbPaymentView>{
  final _picker = ImagePicker();
  String coverNetUrl;

  String _smsCode;
  String _mobile;
  String _name;
  final _countdownKey = GlobalKey<CountdownViewState>();

  String phone;
  @override
  void initState() {
    super.initState();
    UserPhoneCache cache = UserPhoneCache();
    cache.get().then((value){
      phone = value;
    });
    // UsernamePasswordCache cache = UsernamePasswordCache();
    // cache.getArray().then((value) {
    //   phone = value[0];
    // });
  }
  BuildContext ctx;
  int showEdit = 1;

  bool editImage = false;
  var message;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    return Scaffold(
      appBar: AppBar(
        title: Text("${message['text23']}"),
      ),
      backgroundColor: Colors.white,
      body: HttpWidget<PaymentInfo, PaymentInfoBloc>(
        create: (context) => PaymentInfoBloc()..add(IdHttpEvent(widget.index)),
        emptyBuilder: (context){
          ctx = context;
          Widget coverImage;
          if(coverNetUrl == null){
            coverImage = Image.asset(Utils.getImgPath("ic_complaints_add"),width: 100,height: 100,);
          }else{
            coverImage = Image.network(coverNetUrl,width: 100,height: 100,fit: BoxFit.fill,);
          }
          return Column(
            children: [
              Container(
                padding: EdgeInsets.only(left: 17,right: 15),
                height: 110,
                child: Row(
                  children: [
                    Text("${message['text7']}",style: TextStyle(fontSize: 15),),
                    SizedBox(width: 20,),
                    GestureDetector(
                      child: coverImage,
                      onTap: () async{
                        closeKeyboard(context);
                        PickedFile value = await _picker.getImage(source: ImageSource.gallery, imageQuality: 100,);
                        File file = File(value.path);
                        File newFile = await ImageUtils.imageCompressAndGetFile(file);
                        LoadingApi.func(TradRepository().uploadImage(newFile,1), context, complete: (v) {
                          if (v == null) {
                            return;
                          }
                          setState(() {
                            coverNetUrl = v;
                          });
                        });
                      },
                    )
                  ],
                ),
              ),
              Divider(),
              ListTile(
                leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                title: TextField(
                  style: Theme.of(context).textTheme.headline6,
                  maxLines: 1,
                  textAlignVertical: TextAlignVertical.center,
                  textInputAction: TextInputAction.next,
                  autofocus: false,
                  onChanged: (value) {
                    this._name = value;
                  },
                  keyboardType: TextInputType.text,
                  controller: TextEditingController(text: _name),
                  decoration: InputDecoration(
                    fillColor: Colors.transparent,
                    prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                    filled: true,
                    border: OutlineInputBorder(
                      borderSide: BorderSide.none,
                    ),
                    counterText: '',
                    contentPadding: EdgeInsets.all(2),
                    hintText: "${message['text4']}",
                    hintStyle: Theme.of(context).textTheme.bodyText1,
                  ),
                ),
              ),
              Divider(),
              ListTile(
                leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                title: TextField(
                  style: Theme.of(context).textTheme.headline6,
                  maxLines: 1,
                  textAlignVertical: TextAlignVertical.center,
                  textInputAction: TextInputAction.next,
                  autofocus: false,
                  onChanged: (value) {
                    this._mobile = value;
                  },
                  keyboardType: TextInputType.text,
                  controller: TextEditingController(text: _mobile),
                  decoration: InputDecoration(
                    fillColor: Colors.transparent,
                    prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                    filled: true,
                    border: OutlineInputBorder(
                      borderSide: BorderSide.none,
                    ),
                    counterText: '',
                    contentPadding: EdgeInsets.all(2),
                    hintText: "${message['text12']}",
                    hintStyle: Theme.of(context).textTheme.bodyText1,
                  ),
                ),
              ),
              Divider(),
              TextFormField(
                style: TextStyle(color: Colors.black,fontSize: 15),
                maxLines: 1,
                textAlignVertical: TextAlignVertical.center,
                textInputAction: TextInputAction.done,
                // maxLength: 4,
                keyboardType: TextInputType.numberWithOptions(),
                autofocus: false,
                obscureText: false,
                cursorColor: Theme.of(context).primaryColor,
                validator: (value) {
                  return value.length == 0 ? '${message['paymentSms']}' : null;
                },
                onChanged: (value){
                  _smsCode = value;
                },
                controller: TextEditingController(text: _smsCode),
                decoration: InputDecoration(
                  fillColor: Colors.white,
                  filled: true,
                  prefixIconConstraints: BoxConstraints.loose(Size(85, 50)),
                  suffixIconConstraints: BoxConstraints.loose(Size(100, 56)),
                  suffixIcon: CountdownView(
                    key: _countdownKey,
                    hint: Text(
                      "${message['getCode']}",
                      style: TextStyle(color: AppColors.primaryColor, fontSize: 14),
                    ),
                    onPressed: () {
                      closeKeyboard(context);
                      _onGetCode();
                    },
                  ),
                  border: UnderlineInputBorder(
                    borderSide: BorderSide.none,
                    borderRadius: const BorderRadius.all(Radius.circular(24)),
                  ),
                  errorMaxLines: 1,
                  counterText: '',
                  contentPadding: EdgeInsets.only(left: 20, right: 16),
                  hintText: "${message['paymentSms']}",
                  hintStyle: TextStyle(fontSize: 15,color: AppColors.textHintColor),
                  prefixIcon: Center(
                    child: Text(
                        "${message['text13']}",
                        style: TextStyle(color: AppColors.textColor,fontSize: 16)
                    ),
                  ),
                ),
              ),
              Divider(),

              SizedBox(height: 30,),
              SizedBox(
                width: double.infinity,
                height: 42,
                child: ElevatedButton(
                  child: Text("${message['text15']}"),
                  style: ButtonStyle(
                    backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                    shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                  ),
                  onPressed: (){
                    subAlipay();
                  },
                ),
              ).addPadding(EdgeInsets.only(left: 15,right: 15)),
            ],
          );
        },
        child: (context,data){
          ctx = context;
          Widget child;
          if(editImage == false){
            coverNetUrl = data.content;
          }
          if(showEdit == 2){
            child = Column(
              children: [
                Container(
                  padding: EdgeInsets.only(left: 17,right: 15),
                  height: 120,
                  child: Row(
                    children: [
                      Text("${message['text7']}",style: TextStyle(fontSize: 15),),
                      SizedBox(width: 20,),
                      GestureDetector(
                        child: Image.network("$coverNetUrl",width: 110,height: 110,fit: BoxFit.fill,),
                        onTap: () async{
                          closeKeyboard(context);
                          if(data.status == "1"){
                            return;
                          }
                          PickedFile value = await _picker.getImage(source: ImageSource.gallery, imageQuality: 100,);
                          File file = File(value.path);
                          File newFile = await ImageUtils.imageCompressAndGetFile(file);
                          LoadingApi.func(TradRepository().uploadImage(newFile,1), context, complete: (v) {
                            if (v == null) {
                              return;
                            }
                            setState(() {
                              coverNetUrl = v;
                              editImage = true;
                            });
                          });
                        },
                      )
                    ],
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._name = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _name),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text4']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._mobile = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _mobile),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text12']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                TextFormField(
                  style: TextStyle(color: Colors.black,fontSize: 15),
                  maxLines: 1,
                  textAlignVertical: TextAlignVertical.center,
                  textInputAction: TextInputAction.done,
                  // maxLength: 4,
                  keyboardType: TextInputType.numberWithOptions(),
                  autofocus: false,
                  obscureText: false,
                  cursorColor: Theme.of(context).primaryColor,
                  validator: (value) {
                    return value.length == 0 ? '${message['paymentSms']}' : null;
                  },
                  onChanged: (value){
                    _smsCode = value;
                  },
                  controller: TextEditingController(text: _smsCode),
                  decoration: InputDecoration(
                    fillColor: Colors.white,
                    filled: true,
                    prefixIconConstraints: BoxConstraints.loose(Size(85, 50)),
                    suffixIconConstraints: BoxConstraints.loose(Size(100, 56)),
                    suffixIcon: CountdownView(
                      key: _countdownKey,
                      hint: Text(
                        "${message['getCode']}",
                        style: TextStyle(color: AppColors.primaryColor, fontSize: 14),
                      ),
                      onPressed: () {
                        closeKeyboard(context);
                        _onGetCode();
                      },
                    ),
                    border: UnderlineInputBorder(
                      borderSide: BorderSide.none,
                      borderRadius: const BorderRadius.all(Radius.circular(24)),
                    ),
                    errorMaxLines: 1,
                    counterText: '',
                    contentPadding: EdgeInsets.only(left: 20, right: 16),
                    hintText: "${message['paymentSms']}",
                    hintStyle: TextStyle(fontSize: 15,color: AppColors.textHintColor),
                    prefixIcon: Center(
                      child: Text(
                          "${message['text13']}",
                          style: TextStyle(color: AppColors.textColor,fontSize: 16)
                      ),
                    ),
                  ),
                ),
                Divider(),

                SizedBox(height: 30,),
                SizedBox(
                  width: double.infinity,
                  height: 42,
                  child: ElevatedButton(
                    child: Text(data.status == "1" ? "${message['text16']}":"${message['text21']}"),
                    style: ButtonStyle(
                      backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                      shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                    ),
                    onPressed: (){
                      if(data.status == "1"){
                        return;
                      }
                      subAlipay();
                    },
                  ),
                ).addPadding(EdgeInsets.only(left: 15,right: 15)),
              ],
            );
          }else{
            _name = data.real_name;
            _mobile = data.mobile;
            child = Column(
              children: [
                Container(
                  child: Image.network("$coverNetUrl",width: 180,height: 180,fit: BoxFit.fill,),
                ),
                ListTile(
                  leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._name = value;
                    },
                    enabled: false,
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _name),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text4']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._mobile = value;
                    },
                    enabled: false,
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _mobile),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text12']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                SizedBox(height: 30,),
                SizedBox(
                  width: double.infinity,
                  height: 42,
                  child: ElevatedButton(
                    child: Text(data.status == "1" ? "${message['text16']}":"${message['text21']}"),
                    style: ButtonStyle(
                      backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                      shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                    ),
                    onPressed: (){
                      if(data.status == "1"){
                        return;
                      }
                      showEdit = 2;
                      setState(() {});
                    },
                  ),
                ).addPadding(EdgeInsets.only(left: 15,right: 15)),

                Offstage(
                  offstage: data.status == "0" ? false : true,
                  child: Text("${message['text17']}",style: TextStyle(color: AppColors.primaryColor),),
                ),
                SizedBox(height: 8,),
                Offstage(
                  offstage: data.status == "2" ? false : true,
                  child: Text("${message['text29']}",style: TextStyle(color: AppColors.primaryColor),),
                )
              ],
            );
          }
          return child;
        },
      )
    );
  }
  _onGetCode(){
    _countdownKey.currentState.state = CountdownState.loading;
    LoadingApi.func(AuthRepository().getSmsCode(8,phone: phone), context,showLoading: false,complete: (value){
      _countdownKey.currentState.state = CountdownState.countdown;
      ToastUtils.show("$value", context);
    },error: (error){
      _countdownKey.currentState.state = CountdownState.init;
      ToastUtils.show("$error", context);
    });
  }
  subAlipay(){
    if(coverNetUrl == null){
      ToastUtils.show("${message['text28']}", context);
      return;
    }
    if(_name == null){
      ToastUtils.show("${message['text4']}", context);
      return;
    }
    if(_mobile == null){
      ToastUtils.show("${message['text12']}", context);
      return;
    }
    if(_smsCode == null){
      ToastUtils.show("${message['paymentSms']}", context);
      return;
    }
    closeKeyboard(context);
    LoadingApi.func(TradRepository().bindPayment(payment: widget.index,alipayImg: coverNetUrl,code: _smsCode,mobile: _mobile,name: _name), context,complete: (e){
      ToastUtils.show("${message['Success']}", context);
      showEdit = 1;
      editImage = false;
      BlocProvider.of<PaymentInfoBloc>(ctx).add(IdHttpEvent(widget.index));
    },error: (e){
      ToastUtils.show("$e", context);
    });
  }
}




///TNG
class TngPaymentView extends StatefulWidget{
  final int index;
  TngPaymentView({Key key,this.index}):super(key: key);
  @override
  TngPaymentViewState createState() => TngPaymentViewState();
}
class TngPaymentViewState extends State<TngPaymentView>{
  final _picker = ImagePicker();
  String coverNetUrl;

  String _smsCode;
  String _mobile;
  String _name;
  final _countdownKey = GlobalKey<CountdownViewState>();

  String phone;
  @override
  void initState() {
    super.initState();
    UsernamePasswordCache cache = UsernamePasswordCache();
    cache.getArray().then((value) {
      phone = value[0];
    });
  }
  BuildContext ctx;
  int showEdit = 1;

  bool editImage = false;
  var message;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    return Scaffold(
      appBar: AppBar(
        title: Text("${message['text30']}"),
      ),
      backgroundColor: Colors.white,
      body: HttpWidget<PaymentInfo, PaymentInfoBloc>(
        create: (context) => PaymentInfoBloc()..add(IdHttpEvent(widget.index)),
        emptyBuilder: (context){
          ctx = context;
          Widget coverImage;
          if(coverNetUrl == null){
            coverImage = Image.asset(Utils.getImgPath("ic_complaints_add"),width: 100,height: 100,);
          }else{
            coverImage = Image.network(coverNetUrl,width: 100,height: 100,fit: BoxFit.fill,);
          }
          return Column(
            children: [
              Container(
                padding: EdgeInsets.only(left: 17,right: 15),
                height: 110,
                child: Row(
                  children: [
                    Text("${message['text31']}",style: TextStyle(fontSize: 15),),
                    SizedBox(width: 20,),
                    GestureDetector(
                      child: coverImage,
                      onTap: () async{
                        closeKeyboard(context);
                        PickedFile value = await _picker.getImage(source: ImageSource.gallery, imageQuality: 100,);
                        File file = File(value.path);
                        File newFile = await ImageUtils.imageCompressAndGetFile(file);
                        LoadingApi.func(TradRepository().uploadImage(newFile,1), context, complete: (v) {
                          if (v == null) {
                            return;
                          }
                          setState(() {
                            coverNetUrl = v;
                          });
                        });
                      },
                    )
                  ],
                ),
              ),
              Divider(),
              ListTile(
                leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                title: TextField(
                  style: Theme.of(context).textTheme.headline6,
                  maxLines: 1,
                  textAlignVertical: TextAlignVertical.center,
                  textInputAction: TextInputAction.next,
                  autofocus: false,
                  onChanged: (value) {
                    this._name = value;
                  },
                  keyboardType: TextInputType.text,
                  controller: TextEditingController(text: _name),
                  decoration: InputDecoration(
                    fillColor: Colors.transparent,
                    prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                    filled: true,
                    border: OutlineInputBorder(
                      borderSide: BorderSide.none,
                    ),
                    counterText: '',
                    contentPadding: EdgeInsets.all(2),
                    hintText: "${message['text4']}",
                    hintStyle: Theme.of(context).textTheme.bodyText1,
                  ),
                ),
              ),
              Divider(),
              ListTile(
                leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                title: TextField(
                  style: Theme.of(context).textTheme.headline6,
                  maxLines: 1,
                  textAlignVertical: TextAlignVertical.center,
                  textInputAction: TextInputAction.next,
                  autofocus: false,
                  onChanged: (value) {
                    this._mobile = value;
                  },
                  keyboardType: TextInputType.text,
                  controller: TextEditingController(text: _mobile),
                  decoration: InputDecoration(
                    fillColor: Colors.transparent,
                    prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                    filled: true,
                    border: OutlineInputBorder(
                      borderSide: BorderSide.none,
                    ),
                    counterText: '',
                    contentPadding: EdgeInsets.all(2),
                    hintText: "${message['text12']}",
                    hintStyle: Theme.of(context).textTheme.bodyText1,
                  ),
                ),
              ),
              Divider(),
              TextFormField(
                style: TextStyle(color: Colors.black,fontSize: 15),
                maxLines: 1,
                textAlignVertical: TextAlignVertical.center,
                textInputAction: TextInputAction.done,
                // maxLength: 4,
                keyboardType: TextInputType.numberWithOptions(),
                autofocus: false,
                obscureText: false,
                cursorColor: Theme.of(context).primaryColor,
                validator: (value) {
                  return value.length == 0 ? '${message['paymentSms']}' : null;
                },
                onChanged: (value){
                  _smsCode = value;
                },
                controller: TextEditingController(text: _smsCode),
                decoration: InputDecoration(
                  fillColor: Colors.white,
                  filled: true,
                  prefixIconConstraints: BoxConstraints.loose(Size(85, 50)),
                  suffixIconConstraints: BoxConstraints.loose(Size(100, 56)),
                  suffixIcon: CountdownView(
                    key: _countdownKey,
                    hint: Text(
                      "${message['getCode']}",
                      style: TextStyle(color: AppColors.primaryColor, fontSize: 14),
                    ),
                    onPressed: () {
                      closeKeyboard(context);
                      _onGetCode();
                    },
                  ),
                  border: UnderlineInputBorder(
                    borderSide: BorderSide.none,
                    borderRadius: const BorderRadius.all(Radius.circular(24)),
                  ),
                  errorMaxLines: 1,
                  counterText: '',
                  contentPadding: EdgeInsets.only(left: 20, right: 16),
                  hintText: "${message['paymentSms']}",
                  hintStyle: TextStyle(fontSize: 15,color: AppColors.textHintColor),
                  prefixIcon: Center(
                    child: Text(
                        "${message['text13']}",
                        style: TextStyle(color: AppColors.textColor,fontSize: 16)
                    ),
                  ),
                ),
              ),
              Divider(),

              SizedBox(height: 30,),
              SizedBox(
                width: double.infinity,
                height: 42,
                child: ElevatedButton(
                  child: Text("${message['text15']}"),
                  style: ButtonStyle(
                    backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                    shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                  ),
                  onPressed: (){
                    subTng();
                  },
                ),
              ).addPadding(EdgeInsets.only(left: 15,right: 15)),
            ],
          );
        },
        child: (context,data){
          ctx = context;
          Widget child;
          if(editImage == false){
            coverNetUrl = data.content;
          }
          if(showEdit == 2){
            child = Column(
              children: [
                Container(
                  padding: EdgeInsets.only(left: 17,right: 15),
                  height: 120,
                  child: Row(
                    children: [
                      Text("${message['text7']}",style: TextStyle(fontSize: 15),),
                      SizedBox(width: 20,),
                      GestureDetector(
                        child: Image.network("$coverNetUrl",width: 110,height: 110,fit: BoxFit.fill,),
                        onTap: () async{
                          closeKeyboard(context);
                          if(data.status == "1"){
                            return;
                          }
                          PickedFile value = await _picker.getImage(source: ImageSource.gallery, imageQuality: 100,);
                          File file = File(value.path);
                          File newFile = await ImageUtils.imageCompressAndGetFile(file);
                          LoadingApi.func(TradRepository().uploadImage(newFile,1), context, complete: (v) {
                            if (v == null) {
                              return;
                            }
                            setState(() {
                              coverNetUrl = v;
                              editImage = true;
                            });
                          });
                        },
                      )
                    ],
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._name = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _name),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text4']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._mobile = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _mobile),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text12']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                TextFormField(
                  style: TextStyle(color: Colors.black,fontSize: 15),
                  maxLines: 1,
                  textAlignVertical: TextAlignVertical.center,
                  textInputAction: TextInputAction.done,
                  // maxLength: 4,
                  keyboardType: TextInputType.numberWithOptions(),
                  autofocus: false,
                  obscureText: false,
                  cursorColor: Theme.of(context).primaryColor,
                  validator: (value) {
                    return value.length == 0 ? '${message['paymentSms']}' : null;
                  },
                  onChanged: (value){
                    _smsCode = value;
                  },
                  controller: TextEditingController(text: _smsCode),
                  decoration: InputDecoration(
                    fillColor: Colors.white,
                    filled: true,
                    prefixIconConstraints: BoxConstraints.loose(Size(85, 50)),
                    suffixIconConstraints: BoxConstraints.loose(Size(100, 56)),
                    suffixIcon: CountdownView(
                      key: _countdownKey,
                      hint: Text(
                        "${message['getCode']}",
                        style: TextStyle(color: AppColors.primaryColor, fontSize: 14),
                      ),
                      onPressed: () {
                        closeKeyboard(context);
                        _onGetCode();
                      },
                    ),
                    border: UnderlineInputBorder(
                      borderSide: BorderSide.none,
                      borderRadius: const BorderRadius.all(Radius.circular(24)),
                    ),
                    errorMaxLines: 1,
                    counterText: '',
                    contentPadding: EdgeInsets.only(left: 20, right: 16),
                    hintText: "${message['paymentSms']}",
                    hintStyle: TextStyle(fontSize: 15,color: AppColors.textHintColor),
                    prefixIcon: Center(
                      child: Text(
                          "${message['text13']}",
                          style: TextStyle(color: AppColors.textColor,fontSize: 16)
                      ),
                    ),
                  ),
                ),
                Divider(),

                SizedBox(height: 30,),
                SizedBox(
                  width: double.infinity,
                  height: 42,
                  child: ElevatedButton(
                    child: Text(data.status == "1" ? "${message['text16']}":"${message['text21']}"),
                    style: ButtonStyle(
                      backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                      shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                    ),
                    onPressed: (){
                      if(data.status == "1"){
                        return;
                      }
                      subTng();
                    },
                  ),
                ).addPadding(EdgeInsets.only(left: 15,right: 15)),
              ],
            );
          }else{
            _name = data.real_name;
            _mobile = data.mobile;
            child = Column(
              children: [
                Container(
                  child: Image.network("$coverNetUrl",width: 180,height: 180,fit: BoxFit.fill,),
                ),
                ListTile(
                  leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._name = value;
                    },
                    enabled: false,
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _name),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text4']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._mobile = value;
                    },
                    enabled: false,
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _mobile),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text12']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                SizedBox(height: 30,),
                SizedBox(
                  width: double.infinity,
                  height: 42,
                  child: ElevatedButton(
                    child: Text(data.status == "1" ? "${message['text16']}":"${message['text21']}"),
                    style: ButtonStyle(
                      backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                      shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                    ),
                    onPressed: (){
                      if(data.status == "1"){
                        return;
                      }
                      showEdit = 2;
                      setState(() {});
                    },
                  ),
                ).addPadding(EdgeInsets.only(left: 15,right: 15)),

                Offstage(
                  offstage: data.status == "0" ? false : true,
                  child: Text("${message['text17']}",style: TextStyle(color: AppColors.primaryColor),),
                ),
                SizedBox(height: 8,),
                Offstage(
                  offstage: data.status == "2" ? false : true,
                  child: Text("${message['text29']}",style: TextStyle(color: AppColors.primaryColor),),
                )
              ],
            );
          }
          return child;
        },
      )
    );
  }
  _onGetCode(){
    _countdownKey.currentState.state = CountdownState.loading;
    LoadingApi.func(AuthRepository().getSmsCode(8,phone: phone), context,showLoading: false,complete: (value){
      _countdownKey.currentState.state = CountdownState.countdown;
      ToastUtils.show("$value", context);
    },error: (error){
      _countdownKey.currentState.state = CountdownState.init;
      ToastUtils.show("$error", context);
    });
  }
  subTng(){
    if(coverNetUrl == null){
      ToastUtils.show("${message['text28']}", context);
      return;
    }
    if(_name == null){
      ToastUtils.show("${message['text4']}", context);
      return;
    }
    if(_mobile == null){
      ToastUtils.show("${message['text12']}", context);
      return;
    }
    if(_smsCode == null){
      ToastUtils.show("${message['paymentSms']}", context);
      return;
    }
    LoadingApi.func(TradRepository().bindPayment(payment: widget.index,tngImg: coverNetUrl,code: _smsCode,mobile: _mobile,name: _name), context,complete: (e){
      ToastUtils.show("${message['Success']}", context);
      showEdit = 1;
      editImage = false;
      BlocProvider.of<PaymentInfoBloc>(ctx).add(IdHttpEvent(widget.index));
    },error: (e){
      ToastUtils.show("$e", context);
    });
  }
}







///微信
class WxPaymentView extends StatefulWidget{
  final int index;
  WxPaymentView({Key key,this.index}):super(key: key);
  @override
  WxPaymentViewState createState() => WxPaymentViewState();
}
class WxPaymentViewState extends State<WxPaymentView>{

  final _picker = ImagePicker();
  String coverNetUrl;

  String _smsCode;
  String _mobile;
  String _name;
  final _countdownKey = GlobalKey<CountdownViewState>();

  String phone;
  @override
  void initState() {
    super.initState();
    // UsernamePasswordCache cache = UsernamePasswordCache();
    // cache.getArray().then((value) {
    //   phone = value[0];
    // });
    UserPhoneCache cache = UserPhoneCache();
    cache.get().then((value){
      phone = value;
    });
  }
  BuildContext ctx;



  int showEdit = 1;
  bool editImage = false;
  var message;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    return Scaffold(
      appBar: AppBar(
        title: Text("${message['text24']}"),
      ),
      backgroundColor: Colors.white,
      body: HttpWidget<PaymentInfo, PaymentInfoBloc>(
          create: (context) => PaymentInfoBloc()..add(IdHttpEvent(widget.index)),
          emptyBuilder: (context){
            ctx = context;
            Widget coverImage;
            if(coverNetUrl == null){
              coverImage = Image.asset(Utils.getImgPath("ic_complaints_add"),width: 100,height: 100,);
            }else{
              coverImage = Image.network(coverNetUrl,width: 100,height: 100,fit: BoxFit.fill,);
            }
            return Column(
              children: [
                Container(
                  padding: EdgeInsets.only(left: 17,right: 15),
                  height: 110,
                  child: Row(
                    children: [
                      Text("${message['text8']}",style: TextStyle(fontSize: 15),),
                      SizedBox(width: 20,),
                      GestureDetector(
                        child: coverImage,
                        onTap: () async{
                          closeKeyboard(context);
                          PickedFile value = await _picker.getImage(source: ImageSource.gallery, imageQuality: 100,);
                          File file = File(value.path);
                          File newFile = await ImageUtils.imageCompressAndGetFile(file);
                          LoadingApi.func(TradRepository().uploadImage(newFile,1), context, complete: (v) {
                            if (v == null) {
                              return;
                            }
                            setState(() {
                              coverNetUrl = v;
                            });
                          });
                        },
                      )
                    ],
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._name = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _name),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text4']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._mobile = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _mobile),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text12']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                TextFormField(
                  style: TextStyle(color: Colors.black,fontSize: 15),
                  maxLines: 1,
                  textAlignVertical: TextAlignVertical.center,
                  textInputAction: TextInputAction.done,
                  // maxLength: 4,
                  keyboardType: TextInputType.numberWithOptions(),
                  autofocus: false,
                  obscureText: false,
                  cursorColor: Theme.of(context).primaryColor,
                  validator: (value) {
                    return value.length == 0 ? '${message['paymentSms']}' : null;
                  },
                  onChanged: (value){
                    _smsCode = value;
                  },
                  controller: TextEditingController(text: _smsCode),
                  decoration: InputDecoration(
                    fillColor: Colors.white,
                    filled: true,
                    prefixIconConstraints: BoxConstraints.loose(Size(85, 50)),
                    suffixIconConstraints: BoxConstraints.loose(Size(100, 56)),
                    suffixIcon: CountdownView(
                      key: _countdownKey,
                      hint: Text(
                        "${message['getCode']}",
                        style: TextStyle(color: AppColors.primaryColor, fontSize: 14),
                      ),
                      onPressed: () {
                        closeKeyboard(context);
                        _onGetCode();
                      },
                    ),
                    border: UnderlineInputBorder(
                      borderSide: BorderSide.none,
                      borderRadius: const BorderRadius.all(Radius.circular(24)),
                    ),
                    errorMaxLines: 1,
                    counterText: '',
                    contentPadding: EdgeInsets.only(left: 20, right: 16),
                    hintText: "${message['paymentSms']}",
                    hintStyle: TextStyle(fontSize: 15,color: AppColors.textHintColor),
                    prefixIcon: Center(
                      child: Text(
                          "${message['text13']}",
                          style: TextStyle(color: AppColors.textColor,fontSize: 16)
                      ),
                    ),
                  ),
                ),
                Divider(),

                SizedBox(height: 30,),
                SizedBox(
                  width: double.infinity,
                  height: 42,
                  child: ElevatedButton(
                    child: Text("${message['text15']}"),
                    style: ButtonStyle(
                      backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                      shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                    ),
                    onPressed: (){
                      subWx();
                    },
                  ),
                ).addPadding(EdgeInsets.only(left: 15,right: 15)),
              ],
            );
          },
          child: (context, data) {
            ctx = context;
            Widget child;
            if(editImage == false){
              coverNetUrl = data.content;
            }
            if(showEdit == 2){
              child = Column(
                children: [
                  Container(
                    padding: EdgeInsets.only(left: 17,right: 15),
                    height: 120,
                    child: Row(
                      children: [
                        Text("${message['text8']}",style: TextStyle(fontSize: 15),),
                        SizedBox(width: 20,),
                        GestureDetector(
                          child: Image.network("$coverNetUrl",width: 110,height: 110,fit: BoxFit.fill,),
                          onTap: () async{
                            closeKeyboard(context);
                            if(data.status == "1"){
                              return;
                            }
                            PickedFile value = await _picker.getImage(source: ImageSource.gallery, imageQuality: 100,);
                            File file = File(value.path);
                            File newFile = await ImageUtils.imageCompressAndGetFile(file);
                            LoadingApi.func(TradRepository().uploadImage(newFile,1), context, complete: (v) {
                              if (v == null) {
                                return;
                              }
                              setState(() {
                                coverNetUrl = v;
                                editImage = true;
                              });
                            });
                          },
                        )
                      ],
                    ),
                  ),
                  Divider(),
                  ListTile(
                    leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this._name = value;
                      },
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: _name),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "${message['text4']}",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  ListTile(
                    leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this._mobile = value;
                      },
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: _mobile),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "${message['text12']}",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  TextFormField(
                    style: TextStyle(color: Colors.black,fontSize: 15),
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.done,
                    // maxLength: 4,
                    keyboardType: TextInputType.numberWithOptions(),
                    autofocus: false,
                    obscureText: false,
                    cursorColor: Theme.of(context).primaryColor,
                    validator: (value) {
                      return value.length == 0 ? '${message['paymentSms']}' : null;
                    },
                    onChanged: (value){
                      _smsCode = value;
                    },
                    controller: TextEditingController(text: _smsCode),
                    decoration: InputDecoration(
                      fillColor: Colors.white,
                      filled: true,
                      prefixIconConstraints: BoxConstraints.loose(Size(85, 50)),
                      suffixIconConstraints: BoxConstraints.loose(Size(100, 56)),
                      suffixIcon: CountdownView(
                        key: _countdownKey,
                        hint: Text(
                          "${message['getCode']}",
                          style: TextStyle(color: AppColors.primaryColor, fontSize: 14),
                        ),
                        onPressed: () {
                          closeKeyboard(context);
                          _onGetCode();
                        },
                      ),
                      border: UnderlineInputBorder(
                        borderSide: BorderSide.none,
                        borderRadius: const BorderRadius.all(Radius.circular(24)),
                      ),
                      errorMaxLines: 1,
                      counterText: '',
                      contentPadding: EdgeInsets.only(left: 20, right: 16),
                      hintText: "${message['paymentSms']}",
                      hintStyle: TextStyle(fontSize: 15,color: AppColors.textHintColor),
                      prefixIcon: Center(
                        child: Text(
                            "${message['text13']}",
                            style: TextStyle(color: AppColors.textColor,fontSize: 16)
                        ),
                      ),
                    ),
                  ),
                  Divider(),

                  SizedBox(height: 30,),
                  SizedBox(
                    width: double.infinity,
                    height: 42,
                    child: ElevatedButton(
                      child: Text(data.status == "1" ? "${message['text16']}":"${message['text21']}"),
                      style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                        shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                      ),
                      onPressed: (){
                        if(data.status == "1"){
                          return;
                        }
                        subWx();
                      },
                    ),
                  ).addPadding(EdgeInsets.only(left: 15,right: 15)),
                ],
              );
            }else{
              _name = data.real_name;
              _mobile = data.mobile;
              child = Column(
                children: [
                  Container(
                    child: Image.network("${data.content}",width: 180,height: 180,fit: BoxFit.fill,),
                  ),
                  ListTile(
                    leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this._name = value;
                      },
                      enabled: false,
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: _name),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "${message['text4']}",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  ListTile(
                    leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                    title: TextField(
                      style: Theme.of(context).textTheme.headline6,
                      maxLines: 1,
                      textAlignVertical: TextAlignVertical.center,
                      textInputAction: TextInputAction.next,
                      autofocus: false,
                      onChanged: (value) {
                        this._mobile = value;
                      },
                      enabled: false,
                      keyboardType: TextInputType.text,
                      controller: TextEditingController(text: _mobile),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                        filled: true,
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                        counterText: '',
                        contentPadding: EdgeInsets.all(2),
                        hintText: "${message['text12']}",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                      ),
                    ),
                  ),
                  Divider(),
                  SizedBox(height: 30,),
                  SizedBox(
                    width: double.infinity,
                    height: 42,
                    child: ElevatedButton(
                      child: Text(data.status == "1" ? "${message['text16']}":"${message['text21']}"),
                      style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                        shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                      ),
                      onPressed: (){
                        if(data.status == "1"){
                          return;
                        }
                        showEdit = 2;
                        setState(() {});
                      },
                    ),
                  ).addPadding(EdgeInsets.only(left: 15,right: 15)),

                  Offstage(
                    offstage: data.status == "0" ? false : true,
                    child: Text("${message['text17']}",style: TextStyle(color: AppColors.primaryColor),),
                  ),
                  SizedBox(height: 8,),
                  Offstage(
                    offstage: data.status == "2" ? false : true,
                    child: Text("${message['text29']}",style: TextStyle(color: AppColors.primaryColor),),
                  )
                ],
              );
            }
            return child;
          }
      )
    );
  }

  _onGetCode(){
    _countdownKey.currentState.state = CountdownState.loading;
    LoadingApi.func(AuthRepository().getSmsCode(8,phone: phone), context,showLoading: false,complete: (value){
      _countdownKey.currentState.state = CountdownState.countdown;
      ToastUtils.show("$value", context);
    },error: (error){
      _countdownKey.currentState.state = CountdownState.init;
      ToastUtils.show("$error", context);
    });
  }

  subWx(){
    if(coverNetUrl == null){
      ToastUtils.show("${message['text28']}", context);
      return;
    }
    if(_name == null){
      ToastUtils.show("${message['text4']}", context);
      return;
    }
    if(_mobile == null){
      ToastUtils.show("${message['text12']}", context);
      return;
    }
    if(_smsCode == null){
      ToastUtils.show("${message['paymentSms']}", context);
      return;
    }
    closeKeyboard(context);
    LoadingApi.func(TradRepository().bindPayment(payment: widget.index,wechatImg: coverNetUrl,code: _smsCode,mobile: _mobile,name: _name), context,complete: (e){
      ToastUtils.show("${message['Success']}", context);
      showEdit = 1;
      editImage = false;
      BlocProvider.of<PaymentInfoBloc>(ctx).add(IdHttpEvent(widget.index));
    },error: (e){
      ToastUtils.show("$e", context);
    });
  }
}


///usdt
class UsdtPaymentView extends StatefulWidget{
  final int index;
  UsdtPaymentView({Key key,this.index}):super(key: key);
  @override
  UsdtPaymentViewState createState() => UsdtPaymentViewState();
}
class UsdtPaymentViewState extends State<UsdtPaymentView>{
  String url;
  String _smsCode;
  final _countdownKey = GlobalKey<CountdownViewState>();

  String phone;
  String _mobile;
  String _name;
  int showSmsView = 1;
  int showBtn = 1;
  @override
  void initState() {
    super.initState();
    UsernamePasswordCache cache = UsernamePasswordCache();
    cache.getArray().then((value) {
      phone = value[0];
    });
  }
  BuildContext ctx;
  var message;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    return Scaffold(
      appBar: AppBar(
        title: Text("${message['text26']}"),
      ),
      backgroundColor: Colors.white,
      body: HttpWidget<PaymentInfo, PaymentInfoBloc>(
        create: (context) => PaymentInfoBloc()..add(IdHttpEvent(widget.index)),
        emptyBuilder: (context){
          ctx = context;
          return Column(
            children: [
              ListTile(
                leading: Text("${message['text9']}",style: TextStyle(fontSize: 15, ),),
                title: TextField(
                  style: Theme.of(context).textTheme.headline6,
                  maxLines: 1,
                  textAlignVertical: TextAlignVertical.center,
                  textInputAction: TextInputAction.next,
                  autofocus: false,
                  onChanged: (value) {
                    this.url = value;
                  },
                  keyboardType: TextInputType.text,
                  controller: TextEditingController(text: url),
                  decoration: InputDecoration(
                    fillColor: Colors.transparent,
                    prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                    filled: true,
                    border: OutlineInputBorder(
                      borderSide: BorderSide.none,
                    ),
                    counterText: '',
                    contentPadding: EdgeInsets.all(2),
                    hintText: "${message['text10']}",
                    hintStyle: Theme.of(context).textTheme.bodyText1,
                  ),
                ),
              ),
              Divider(),
              ListTile(
                leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                title: TextField(
                  style: Theme.of(context).textTheme.headline6,
                  maxLines: 1,
                  textAlignVertical: TextAlignVertical.center,
                  textInputAction: TextInputAction.next,
                  autofocus: false,
                  onChanged: (value) {
                    this._name = value;
                  },
                  keyboardType: TextInputType.text,
                  controller: TextEditingController(text: _name),
                  decoration: InputDecoration(
                    fillColor: Colors.transparent,
                    prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                    filled: true,
                    border: OutlineInputBorder(
                      borderSide: BorderSide.none,
                    ),
                    counterText: '',
                    contentPadding: EdgeInsets.all(2),
                    hintText: "${message['text4']}",
                    hintStyle: Theme.of(context).textTheme.bodyText1,
                  ),
                ),
              ),
              Divider(),
              ListTile(
                leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                title: TextField(
                  style: Theme.of(context).textTheme.headline6,
                  maxLines: 1,
                  textAlignVertical: TextAlignVertical.center,
                  textInputAction: TextInputAction.next,
                  autofocus: false,
                  onChanged: (value) {
                    this._mobile = value;
                  },
                  keyboardType: TextInputType.text,
                  controller: TextEditingController(text: _mobile),
                  decoration: InputDecoration(
                    fillColor: Colors.transparent,
                    prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                    filled: true,
                    border: OutlineInputBorder(
                      borderSide: BorderSide.none,
                    ),
                    counterText: '',
                    contentPadding: EdgeInsets.all(2),
                    hintText: "${message['text12']}",
                    hintStyle: Theme.of(context).textTheme.bodyText1,
                  ),
                ),
              ),
              Divider(),
              TextFormField(
                style: TextStyle(color: Colors.black,fontSize: 15),
                maxLines: 1,
                textAlignVertical: TextAlignVertical.center,
                textInputAction: TextInputAction.done,
                // maxLength: 4,
                keyboardType: TextInputType.numberWithOptions(),
                autofocus: false,
                obscureText: false,
                cursorColor: Theme.of(context).primaryColor,
                validator: (value) {
                  return value.length == 0 ? '${message['paymentSms']}' : null;
                },
                onChanged: (value){
                  _smsCode = value;
                },
                controller: TextEditingController(text: _smsCode),
                decoration: InputDecoration(
                  fillColor: Colors.white,
                  filled: true,
                  prefixIconConstraints: BoxConstraints.loose(Size(85, 50)),
                  suffixIconConstraints: BoxConstraints.loose(Size(100, 56)),
                  suffixIcon: CountdownView(
                    key: _countdownKey,
                    hint: Text(
                      "${message['getCode']}",
                      style: TextStyle(color: AppColors.primaryColor, fontSize: 14),
                    ),
                    onPressed: () {
                      closeKeyboard(context);
                      _onGetCode();
                    },
                  ),
                  border: UnderlineInputBorder(
                    borderSide: BorderSide.none,
                    borderRadius: const BorderRadius.all(Radius.circular(24)),
                  ),
                  errorMaxLines: 1,
                  counterText: '',
                  contentPadding: EdgeInsets.only(left: 20, right: 16),
                  hintText: "${message['paymentSms']}",
                  hintStyle: TextStyle(fontSize: 15,color: AppColors.textHintColor),
                  prefixIcon: Center(
                    child: Text(
                        "${message['text13']}",
                        style: TextStyle(color: AppColors.textColor,fontSize: 16)
                    ),
                  ),
                ),
              ),
              Divider(),

              SizedBox(height: 30,),
              SizedBox(
                width: double.infinity,
                height: 42,
                child: ElevatedButton(
                  child: Text("${message['text15']}"),
                  style: ButtonStyle(
                    backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                    shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                  ),
                  onPressed: (){
                    subUsdt();
                  },
                ),
              ).addPadding(EdgeInsets.only(left: 15,right: 15)),
            ],
          );
        },
        child: (context,data){
          ctx = context;
          if(showSmsView == 1){
            url = data.content;
            _name = data.real_name;
            _mobile = data.mobile;
            return Column(
              children: [
                ListTile(
                  leading: Text("${message['text9']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this.url = value;
                    },
                    enabled: false,
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: url),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text10']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._name = value;
                    },
                    enabled: false,
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _name),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text4']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._mobile = value;
                    },
                    enabled: false,
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _mobile),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text12']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),

                SizedBox(height: 30,),
                Offstage(
                  offstage: showBtn == 1 ? false : true,
                  child: SizedBox(
                    width: double.infinity,
                    height: 42,
                    child: ElevatedButton(
                      child: Text(data.status == "1" ? "${message['text16']}" : "${message['text21']}"),
                      style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                        shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                      ),
                      onPressed: (){
                        if(data.status == "1"){
                          return;
                        }
                        showSmsView = 2;
                        showBtn = 2;
                        setState(() {});
                      },
                    ),
                  ).addPadding(EdgeInsets.only(left: 15,right: 15)),
                ),
                SizedBox(height: 3,),
                Offstage(
                  offstage: data.status == "0" ? false : true,
                  child: Text("${message['text17']}",style: TextStyle(color: AppColors.primaryColor),),
                ),
                SizedBox(height: 8,),
                Offstage(
                  offstage: data.status == "2" ? false : true,
                  child: Text("${message['text29']}",style: TextStyle(color: AppColors.primaryColor),),
                )
              ],
            );
          }else{
            return Column(
              children: [
                ListTile(
                  leading: Text("${message['text9']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this.url = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: url),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text10']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text3']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._name = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _name),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text4']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                ListTile(
                  leading: Text("${message['text11']}",style: TextStyle(fontSize: 15, ),),
                  title: TextField(
                    style: Theme.of(context).textTheme.headline6,
                    maxLines: 1,
                    textAlignVertical: TextAlignVertical.center,
                    textInputAction: TextInputAction.next,
                    autofocus: false,
                    onChanged: (value) {
                      this._mobile = value;
                    },
                    keyboardType: TextInputType.text,
                    controller: TextEditingController(text: _mobile),
                    decoration: InputDecoration(
                      fillColor: Colors.transparent,
                      prefixIconConstraints: BoxConstraints.loose(Size(80, 50)),
                      filled: true,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                      counterText: '',
                      contentPadding: EdgeInsets.all(2),
                      hintText: "${message['text12']}",
                      hintStyle: Theme.of(context).textTheme.bodyText1,
                    ),
                  ),
                ),
                Divider(),
                Offstage(
                    offstage: showSmsView  == 2 ? false : true,
                    child: Column(
                      children: [
                        TextFormField(
                          style: TextStyle(color: Colors.black,fontSize: 15),
                          maxLines: 1,
                          textAlignVertical: TextAlignVertical.center,
                          textInputAction: TextInputAction.done,
                          // maxLength: 4,
                          keyboardType: TextInputType.numberWithOptions(),
                          autofocus: false,
                          obscureText: false,
                          cursorColor: Theme.of(context).primaryColor,
                          validator: (value) {
                            return value.length == 0 ? '${message['paymentSms']}' : null;
                          },
                          onChanged: (value){
                            _smsCode = value;
                          },
                          controller: TextEditingController(text: _smsCode),
                          decoration: InputDecoration(
                            fillColor: Colors.white,
                            filled: true,
                            prefixIconConstraints: BoxConstraints.loose(Size(85, 50)),
                            suffixIconConstraints: BoxConstraints.loose(Size(100, 56)),
                            suffixIcon: CountdownView(
                              key: _countdownKey,
                              hint: Text(
                                "${message['getCode']}",
                                style: TextStyle(color: AppColors.primaryColor, fontSize: 14),
                              ),
                              onPressed: () {
                                closeKeyboard(context);
                                _onGetCode();
                              },
                            ),
                            border: UnderlineInputBorder(
                              borderSide: BorderSide.none,
                              borderRadius: const BorderRadius.all(Radius.circular(24)),
                            ),
                            errorMaxLines: 1,
                            counterText: '',
                            contentPadding: EdgeInsets.only(left: 20, right: 16),
                            hintText: "${message['paymentSms']}",
                            hintStyle: TextStyle(fontSize: 15,color: AppColors.textHintColor),
                            prefixIcon: Center(
                              child: Text(
                                  "${message['text13']}",
                                  style: TextStyle(color: AppColors.textColor,fontSize: 16)
                              ),
                            ),
                          ),
                        ),
                      ],
                    )
                ),


                SizedBox(height: 30,),
                Offstage(
                  offstage: showBtn == 1 ? false : true,
                  child: SizedBox(
                    width: double.infinity,
                    height: 42,
                    child: ElevatedButton(
                      child: Text(data.status == "1" ? "${message['text16']}" : "${message['text21']}"),
                      style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                        shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                      ),
                      onPressed: (){
                        if(data.status == "1"){
                          return;
                        }
                        showSmsView = 2;
                        showBtn = 2;
                        setState(() {});
                      },
                    ),
                  ).addPadding(EdgeInsets.only(left: 15,right: 15)),
                ),
                Offstage(
                  offstage: showBtn == 2 ? false : true,
                  child: SizedBox(
                    width: double.infinity,
                    height: 42,
                    child: ElevatedButton(
                      child: Text(data.status == "1" ? "${message['text16']}" : "${message['text21']}"),
                      style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                        shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),//圆角弧度
                      ),
                      onPressed: (){
                        if(data.status == "1"){
                          return;
                        }

                        subUsdt();
                      },
                    ),
                  ).addPadding(EdgeInsets.only(left: 15,right: 15)),
                ),

                SizedBox(height: 3,),
                Offstage(
                  offstage: data.status == "0" ? false : true,
                  child: Text("${message['text17']}",style: TextStyle(color: AppColors.primaryColor),),
                ),
                SizedBox(height: 8,),
                Offstage(
                  offstage: data.status == "2" ? false : true,
                  child: Text("${message['text29']}",style: TextStyle(color: AppColors.primaryColor),),
                )
              ],
            );
          }
        },
      )
    );
  }
  _onGetCode(){
    _countdownKey.currentState.state = CountdownState.loading;
    LoadingApi.func(AuthRepository().getSmsCode(8,phone: phone), context,showLoading: false,complete: (value){
      _countdownKey.currentState.state = CountdownState.countdown;
      ToastUtils.show("$value", context);
    },error: (error){
      _countdownKey.currentState.state = CountdownState.init;
      ToastUtils.show("$error", context);
    });
  }

  subUsdt(){
    if(url == null){
      ToastUtils.show("${message['text10']}", context);
      return;
    }
    if(_name == null){
      ToastUtils.show("${message['text4']}", context);
      return;
    }
    if(_mobile == null){
      ToastUtils.show("${message['text12']}", context);
      return;
    }
    if(_smsCode == null){
      ToastUtils.show("${message['paymentSms']}", context);
      return;
    }
    LoadingApi.func(TradRepository().bindPayment(payment: widget.index,usdtWallet: url,code: _smsCode,mobile: _mobile,name: _name), context,complete: (e){
      ToastUtils.show("${message['Success']}", context);
      showSmsView = 1;
      showBtn = 1;
      BlocProvider.of<PaymentInfoBloc>(ctx).add(IdHttpEvent(widget.index));
    },error: (e){
      ToastUtils.show("$e", context);
    });
  }
}